/**
 * futures : masterlink.futures.vo.EmpSetting.java
 */
package masterlink.futures.vo;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.Table;

import baytony.util.Util;

/**
 * TODO Write the description
 *
 * @author : tonyyang
 * Create date : 2011/11/30
 * @version 1.0.0	
 */
@Entity
@Table(name="SYS_EMP_SETTING")
public class EmpSetting implements Serializable{

	private static final long serialVersionUID = -5997339367099570124L;
	private static final String empty="000000000000000000000000000000";
	@EmbeddedId
	private PK id;
	@Column(name="setting1")
	private String setting1=empty;
	@Column(name="setting2")
	private String setting2=empty;
	
	public EmpSetting() {
	}
	
	public EmpSetting(PK id) {
		this.id=id;
	}
	
	/**
	 * @return the id
	 */
	public PK getId() {
		return id;
	}

	/**
	 * @param id the id to set
	 */
	public void setId(PK id) {
		this.id = id;
	}

	/**
	 * @return the setting1
	 */
	public String getSetting1() {
		return setting1;
	}

	/**
	 * @param setting1 the setting1 to set
	 */
	public void setSetting1(String setting1) {
		this.setting1 = setting1;
	}

	/**
	 * @return the setting2
	 */
	public String getSetting2() {
		return setting2;
	}

	/**
	 * @param setting2 the setting2 to set
	 */
	public void setSetting2(String setting2) {
		this.setting2 = setting2;
	}
	
	public void addSetting1(Integer index){
		setting1=replaceAt(setting1,index,'1');
	}
	
	public void addSetting2(Integer index){
		setting2=replaceAt(setting2,index,'1');
	}
	
	public void removeSetting1(Integer index){
		setting1=replaceAt(setting1,index,'0');
	}
	
	public void removeSetting2(Integer index){
		setting2=replaceAt(setting2,index,'0');
	}
	
	private String replaceAt(String msg,Integer index,char replace){
		if(index!=null){
			if(Util.isEmptyString(msg)){
				msg=empty;
			}
			char[] all=msg.toCharArray();
			all[index-1]=replace;
			return String.valueOf(all);
		}
		return msg;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		StringBuilder builder = new StringBuilder();
		builder.append("EmpSetting [id=");
		builder.append(id);
		builder.append(", setting1=");
		builder.append(setting1);
		builder.append(", setting2=");
		builder.append(setting2);
		builder.append("]");
		return builder.toString();
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (!(obj instanceof EmpSetting))
			return false;
		EmpSetting other = (EmpSetting) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}
	public static class PK implements Serializable{
		
		private static final long serialVersionUID = 2433047679158421004L;
		@Column(name="empno")
		private String empno;
		@Column(name="fun_id")
		private Long funId;
		
		public PK() {
		}
		
		public PK(String empno,Long funId) {
			this.empno=empno;
			this.funId=funId;
		}
		
		/**
		 * @return the empno
		 */
		public String getEmpno() {
			return empno;
		}
		/**
		 * @param empno the empno to set
		 */
		public void setEmpno(String empno) {
			this.empno = empno;
		}
		/**
		 * @return the funId
		 */
		public Long getFunId() {
			return funId;
		}
		/**
		 * @param funId the funId to set
		 */
		public void setFunId(Long funId) {
			this.funId = funId;
		}
		/* (non-Javadoc)
		 * @see java.lang.Object#toString()
		 */
		@Override
		public String toString() {
			StringBuilder builder = new StringBuilder();
			builder.append("PK [empno=");
			builder.append(empno);
			builder.append(", funId=");
			builder.append(funId);
			builder.append("]");
			return builder.toString();
		}
		/* (non-Javadoc)
		 * @see java.lang.Object#hashCode()
		 */
		@Override
		public int hashCode() {
			final int prime = 31;
			int result = 1;
			result = prime * result + ((empno == null) ? 0 : empno.hashCode());
			result = prime * result + ((funId == null) ? 0 : funId.hashCode());
			return result;
		}
		/* (non-Javadoc)
		 * @see java.lang.Object#equals(java.lang.Object)
		 */
		@Override
		public boolean equals(Object obj) {
			if (this == obj)
				return true;
			if (obj == null)
				return false;
			if (!(obj instanceof PK))
				return false;
			PK other = (PK) obj;
			if (empno == null) {
				if (other.empno != null)
					return false;
			} else if (!empno.equals(other.empno))
				return false;
			if (funId == null) {
				if (other.funId != null)
					return false;
			} else if (!funId.equals(other.funId))
				return false;
			return true;
		}
		
	}
	
}
